//
//  StartAnimationViewController.m
//  W2MD
//
//  Created by zhudongwei on 14/12/3.
//  Copyright (c) 2014年 zhudongwei. All rights reserved.
//

#import "StartAnimationViewController.h"
#import "Utility.h"
@interface StartAnimationViewController ()
{
    int  i;
    UIImageView *ivt;
    UIImageView *ivs;
}
@end

@implementation StartAnimationViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
//    CALayer *layer = [CALayer layer];
//    [self.view.layer addSublayer:layer];
//    
//    i = 0;
//    
//    // 设置边界
//    [layer setBounds:CGRectMake(0, 0, 320, 568)];
//    // 设置背景颜色
//    //[layer setBackgroundColor:[UIColor redColor].CGColor];
//    // 设置中心点,如果没有设置，默认是图形的中心点
//    [layer setPosition:CGPointMake(160, 668)];
//    // 设置内容
//    UIImage *image = [UIImage imageNamed:@"tu12.png"];
//    [layer setContents:(id)image.CGImage];
//    // 设置锚点AnchorPoint这个是定位点，在0到1之间。默认是0.5,0.5,表示图形的中心点。
//    // 如果是1，1表示右下角点。如果是0,0表示左上角点。图层的定位就是根据Bounds,position
//    // ,anchorpoint这几个属性来确定的。
//    [layer setAnchorPoint:CGPointMake(0.5, 1.2)];
//    self.mylayer = layer;
//    // 旋转模式是顺时针方向。
//    //[self.mylayer setTransform:CATransform3DMakeRotation(M_PI_4, 0, 0, 1)];
    // 使用keypath方式设置图层旋转
    
    //[self.mylayersetValue:@(M_PI_4)forKeyPath:@"transform.rotation.z"];
    
    i = 0;
    
    ivt = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 568)];
    [ivt.layer setPosition:CGPointMake(160, 668)];
    [ivt setImage:[UIImage imageNamed:@"ats1.png"]];
    [ivt.layer setAnchorPoint:CGPointMake(0.5, 1.2)];
    ivt.userInteractionEnabled = YES;
    [self.view addSubview:ivt];
    
    
    ivs = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 568)];
    [ivs.layer setPosition:CGPointMake(160, 668)];
    [ivs setImage:[UIImage imageNamed:@"ats2.png"]];
    [ivs.layer setAnchorPoint:CGPointMake(0.5, 1.2)];
    ivs.userInteractionEnabled = YES;
    [self.view addSubview:ivs];
    
    
    [UIView animateWithDuration:0.1 animations:^{
        CGAffineTransform at =CGAffineTransformMakeRotation(M_PI_2);
        [ivs setTransform:at];
    } completion:^(BOOL finished) {
        
    }];

    
    
    
    UISwipeGestureRecognizer *swipeGes = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeAction:)];
    [swipeGes setDirection:UISwipeGestureRecognizerDirectionLeft];
    [self.view addGestureRecognizer:swipeGes];
}

-(void)swipeAction:(UISwipeGestureRecognizer*)ges
{
    NSLog(@"-----------------");
    self.view.userInteractionEnabled = NO;
    switch (i) {
        case 0:
        {
            [UIView animateWithDuration:1.f animations:^{
                CGAffineTransform at =CGAffineTransformMakeRotation(-M_PI_2);
                [ivt setTransform:at];
                CGAffineTransform at1 =CGAffineTransformMakeRotation(0);
                [ivs setTransform:at1];
            } completion:^(BOOL finished) {
                i = i+1;
                [ivt setImage:[UIImage imageNamed:@"ats3.png"]];
                CGAffineTransform at =CGAffineTransformMakeRotation(-M_PI_2*3);
                [ivt setTransform:at];
                self.view.userInteractionEnabled = YES;
            }];
        }
            break;
        case 1:
        {
            [UIView animateWithDuration:1.f animations:^{
                CGAffineTransform at =CGAffineTransformMakeRotation(-M_PI_2*4);
                [ivt setTransform:at];
                CGAffineTransform at1 =CGAffineTransformMakeRotation(-M_PI_2);
                [ivs setTransform:at1];
            } completion:^(BOOL finished) {
                i = i+1;
                [ivs setImage:[UIImage imageNamed:@"ats4.png"]];
                CGAffineTransform at =CGAffineTransformMakeRotation(-M_PI_2*3);
                [ivs setTransform:at];
                self.view.userInteractionEnabled = YES;
            }];
        }
            break;
        case 2:
        {
            [UIView animateWithDuration:1.f animations:^{
                CGAffineTransform at =CGAffineTransformMakeRotation(-M_PI_2*5);
                [ivt setTransform:at];
                CGAffineTransform at1 =CGAffineTransformMakeRotation(-M_PI_2*4);
                [ivs setTransform:at1];
            } completion:^(BOOL finished) {
                i = i+1;
                [ivt setImage:[UIImage imageNamed:@"ats5.png"]];
                CGAffineTransform at =CGAffineTransformMakeRotation(-M_PI_2*7);
                [ivt setTransform:at];
                self.view.userInteractionEnabled = YES;
            }];
            
        }
            break;
        case 3:
        {
            [UIView animateWithDuration:1.f animations:^{
                CGAffineTransform at =CGAffineTransformMakeRotation(-M_PI_2*8);
                [ivt setTransform:at];
                CGAffineTransform at1 =CGAffineTransformMakeRotation(-M_PI_2*5);
                [ivs setTransform:at1];
            } completion:^(BOOL finished) {
                i = i+1;
                [ivs setImage:[UIImage imageNamed:@"ats6.png"]];
                CGAffineTransform at =CGAffineTransformMakeRotation(-M_PI_2*7);
                [ivs setTransform:at];
                self.view.userInteractionEnabled = YES;
            }];
        }
            break;
        case 4:
        {
            [UIView animateWithDuration:1.f animations:^{
                CGAffineTransform at =CGAffineTransformMakeRotation(-M_PI_2*9);
                [ivt setTransform:at];
                CGAffineTransform at1 =CGAffineTransformMakeRotation(-M_PI_2*8);
                [ivs setTransform:at1];
            } completion:^(BOOL finished) {
                i = i+1;
                [ivt setImage:[UIImage imageNamed:@"sou2.png"]];
                CGAffineTransform at =CGAffineTransformMakeRotation(-M_PI_2*7);
                [ivt setTransform:at];
                self.view.userInteractionEnabled = YES;
            }];
        }
            break;
        default:
        {
            [self dismissViewControllerAnimated:YES completion:^{
                //[Utility showHelpWith:@"help1@2x.png"];
            }];
        }
            break;

    }

}

//- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
//{
//    switch (i) {
//        case 0:
//        {
//            [UIView animateWithDuration:1.2f animations:^{
//                CGAffineTransform at =CGAffineTransformMakeRotation(-M_PI_2);
//                [ivt setTransform:at];
//                CGAffineTransform at1 =CGAffineTransformMakeRotation(0);
//                [ivs setTransform:at1];
//            } completion:^(BOOL finished) {
//                i = i+1;
//                [ivt setImage:[UIImage imageNamed:@"tu22.png"]];
//                CGAffineTransform at =CGAffineTransformMakeRotation(-M_PI_2*3);
//                [ivt setTransform:at];
//            }];
//        }
//            break;
//        case 1:
//        {
//            [UIView animateWithDuration:1.2f animations:^{
//                CGAffineTransform at =CGAffineTransformMakeRotation(-M_PI_2*4);
//                [ivt setTransform:at];
//                CGAffineTransform at1 =CGAffineTransformMakeRotation(-M_PI_2);
//                [ivs setTransform:at1];
//            } completion:^(BOOL finished) {
//                i = i+1;
//                [ivs setImage:[UIImage imageNamed:@"sou2.png"]];
//                CGAffineTransform at =CGAffineTransformMakeRotation(-M_PI_2*3);
//                [ivs setTransform:at];
//            }];
//        }
//            break;
//        case 2:
//        {
//            [UIView animateWithDuration:1.2f animations:^{
//                CGAffineTransform at =CGAffineTransformMakeRotation(-M_PI_2*5);
//                [ivt setTransform:at];
//                CGAffineTransform at1 =CGAffineTransformMakeRotation(-M_PI_2*4);
//                [ivs setTransform:at1];
//            } completion:^(BOOL finished) {
//                i = i+1;
//                [ivt setImage:[UIImage imageNamed:@"tu32.png"]];
//                CGAffineTransform at =CGAffineTransformMakeRotation(-M_PI_2*7);
//                [ivt setTransform:at];
//            }];
//            
//        }
//            break;
//        case 3:
//        {
//            [UIView animateWithDuration:1.2f animations:^{
//                CGAffineTransform at =CGAffineTransformMakeRotation(-M_PI_2*8);
//                [ivt setTransform:at];
//                CGAffineTransform at1 =CGAffineTransformMakeRotation(-M_PI_2*5);
//                [ivs setTransform:at1];
//            } completion:^(BOOL finished) {
//                i = i+1;
//                [ivs setImage:[UIImage imageNamed:@"sou1.png"]];
//                CGAffineTransform at =CGAffineTransformMakeRotation(-M_PI_2*7);
//                [ivs setTransform:at];
//            }];
//        }
//            break;
//        case 4:
//        {
//            [UIView animateWithDuration:1.2f animations:^{
//                CGAffineTransform at =CGAffineTransformMakeRotation(-M_PI_2*9);
//                [ivt setTransform:at];
//                CGAffineTransform at1 =CGAffineTransformMakeRotation(-M_PI_2*8);
//                [ivs setTransform:at1];
//            } completion:^(BOOL finished) {
//                i = i+1;
//                [ivt setImage:[UIImage imageNamed:@"sou2.png"]];
//                CGAffineTransform at =CGAffineTransformMakeRotation(-M_PI_2*7);
//                [ivt setTransform:at];
//            }];
//        }
//            break;
//        default:
//            break;
//    }
//
//}




//- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
//{
//    // 这个动作有动画效果。有瘾式动画，这个动画执行的时间是0.25秒。是图层的隐式动画
//    if (self.mylayer.anchorPoint.x == 0) {
//        self.mylayer.anchorPoint = CGPointMake(1, 1);
//    } else {
//        self.mylayer.anchorPoint = CGPointMake(0, 0);
//    }
    
    
//    [CATransaction begin];
//    [CATransaction setAnimationDuration:1.5];
//    //[UIView animateWithDuration:2.5 animations:^{
//        [self.mylayer setTransform:CATransform3DMakeRotation(M_PI_2*(i+1), 0, 0, 1)];
//    //}];
//    [CATransaction commit];
//    i=i+1;
//    UIImage *image = [UIImage imageNamed:@"tu22.png"];
//    [self.mylayer setContents:(id)image.CGImage];
    
//    [UIView animateWithDuration:1.5 animations:^{
//        CGAffineTransform at =CGAffineTransformMakeRotation(M_PI/2);
//        //at =CGAffineTransformTranslate(at,200,0);
//        [iv setTransform:at];
//
//    }];
    
//    switch (i) {
//        case 0:
//        {
//            [UIView animateWithDuration:1.5 animations:^{
//                CGAffineTransform at =CGAffineTransformMakeRotation(M_PI_2);
//                [iv setTransform:at];
//            } completion:^(BOOL finished) {
//                if (finished) {
//                    i=i+1;
//                    [iv setImage:[UIImage imageNamed:@"sou3.png"]];
//                    CGAffineTransform at =CGAffineTransformMakeRotation(M_PI_2*3);
//                    [iv setTransform:at];
//                }
//            }];
//        }
//            break;
//        case 1:
//        {
//            [UIView animateWithDuration:1.5 animations:^{
//                CGAffineTransform at =CGAffineTransformMakeRotation(M_PI_2*4);
//                [iv setTransform:at];
//            } completion:^(BOOL finished) {
//                if (finished) {
//                    i=i+1;
//                }
//            }];
//        }
//            break;
//        case 2:
//        {
//            [UIView animateWithDuration:1.5 animations:^{
//                CGAffineTransform at =CGAffineTransformMakeRotation(M_PI_2*5);
//                [iv setTransform:at];
//            } completion:^(BOOL finished) {
//                if (finished) {
//                    i=i+1;
//                    [iv setImage:[UIImage imageNamed:@"tu22.png"]];
//                    CGAffineTransform at =CGAffineTransformMakeRotation(M_PI_2*7);
//                    [iv setTransform:at];
//                }
//            }];
//        }
//            break;
//        case 3:
//        {
//            
//            [UIView animateWithDuration:1.5 animations:^{
//                CGAffineTransform at =CGAffineTransformMakeRotation(M_PI_2*8);
//                [iv setTransform:at];
//            } completion:^(BOOL finished) {
//                if (finished) {
//                    i=i+1;
//                }
//            }];
//            
//
//        }
//            break;
//        case 4:
//        {
//            
//            [UIView animateWithDuration:1.5 animations:^{
//                CGAffineTransform at =CGAffineTransformMakeRotation(M_PI_2*9);
//                [iv setTransform:at];
//            } completion:^(BOOL finished) {
//                if (finished) {
//                    i=i+1;
//                    [iv setImage:[UIImage imageNamed:@"sou2.png"]];
//                    CGAffineTransform at =CGAffineTransformMakeRotation(M_PI_2*11);
//                    [iv setTransform:at];
//                }
//            }];
//        }
//            break;
//        case 5:
//        {
//            [UIView animateWithDuration:1.5 animations:^{
//                CGAffineTransform at =CGAffineTransformMakeRotation(M_PI_2*12);
//                [iv setTransform:at];
//            } completion:^(BOOL finished) {
//                if (finished) {
//                    i=i+1;
//                }
//            }];
//        }
//            break;
//        case 6:
//        {
//            
//            [UIView animateWithDuration:1.5 animations:^{
//                CGAffineTransform at =CGAffineTransformMakeRotation(M_PI_2*13);
//                [iv setTransform:at];
//            } completion:^(BOOL finished) {
//                if (finished) {
//                    i=i+1;
//                    [iv setImage:[UIImage imageNamed:@"tu32.png"]];
//                    CGAffineTransform at =CGAffineTransformMakeRotation(M_PI_2*15);
//                    [iv setTransform:at];
//                }
//            }];
//        }
//            break;
//        case 7:
//        {
//            [UIView animateWithDuration:1.5 animations:^{
//                CGAffineTransform at =CGAffineTransformMakeRotation(M_PI_2*16);
//                [iv setTransform:at];
//            } completion:^(BOOL finished) {
//                if (finished) {
//                    i=i+1;
//                }
//            }];
//        }
//            break;
//        case 8:
//        {
//            
//            [UIView animateWithDuration:1.5 animations:^{
//                CGAffineTransform at =CGAffineTransformMakeRotation(M_PI_2*17);
//                [iv setTransform:at];
//            } completion:^(BOOL finished) {
//                if (finished) {
//                    i=i+1;
//                    [iv setImage:[UIImage imageNamed:@"sou3.png"]];
//                    CGAffineTransform at =CGAffineTransformMakeRotation(M_PI_2*19);
//                    [iv setTransform:at];
//                }
//            }];
//        }
//            break;
//        case 9:
//        {
//            
//            [UIView animateWithDuration:1.5 animations:^{
//                CGAffineTransform at =CGAffineTransformMakeRotation(M_PI_2*20);
//                [iv setTransform:at];
//            } completion:^(BOOL finished) {
//                if (finished) {
//                    i=i+1;
//                }
//            }];
//        }
//            break;
//        default:
//        {
//            [self dismissViewControllerAnimated:YES completion:^{
//                
//            }];
//        }
//            break;
//    }
//
//}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
